<?php
error_reporting(0);
header("Access-Control-Allow-Origin:*");
if(empty($_POST)){
	exit("");	
}else{
	$data = $_POST;
}

//商务通 引导页面的 医生 头像 绝对地址
$swt_doc_head = 'http://www.amnvren.com/shb/images/doctor.jpg';
//商务通 引导页面的 访客 头像 绝对地址
$swt_cus_head = 'http://www.amnvren.com/shb/images/user_head_img.jpg';
//商务通 第一句引导语
$swt_first_msg = '在的!';
//商务通 第二句引导语
$swt_sec_msg = '请说,有什么问题?今年多大年龄了?';
//商务通 第三句引导语
$swt_thr_msg = '你好!';
//商务通 第四句引导语
$swt_for_msg = '或者留个微信,我朋友圈有相关信息';

$platform = strtolower($data['platform']);
if(strstr($platform,'win') || $data["sear_wd"]==""){

	
	$arr_res['code'] = 0;
	
	$arr_res['con'] = "";
		
	
	
}else{
	$arr_res['code'] = 1;
	$arr_res['con'] = "var str='';var input_wd = '".urldecode($data["input_wd"])."';var search_wd = '".urldecode($data["sear_wd"])."';
if (input_wd != \"000\" && input_wd != \"111\") {
	window.input_wd = input_wd;
} else {
	window.input_wd = '';
	input_wd = '';
}
window.search_wd = search_wd;

search_wd = '".$swt_first_msg."';

if (window.search_wd != \"\") {
	str += '<div style=\"margin-right:10px;\" class=\"msg-box\">    <div class=\"msg-client\">  <div class=\"client-avatar\"><img src=\"".$swt_cus_head."\" style=\"width:36px;\" width=\"40px\"></div>      <div class=\"arrow_box\">            <div class=\"text\">' + window.search_wd + '</div>        </div>    </div></div>';
}
str += '<div class=\"msg-box\">    <div class=\"msg-agent\">        <div class=\"agent-avatar\">            <img src=\"".$swt_doc_head."\" width=\"40px\">        </div>        <div class=\"arrow_box_left\" style=\"margin-left:50px;\">            <div class=\"text1\"></div><div class=\"text\">' + search_wd + '</div>        </div>    </div></div>';
str += '<div class=\"msg-box\">    <div class=\"msg-agent\">        <div class=\"agent-avatar\">            <img src=\"".$swt_doc_head."\" width=\"40px\">        </div>        <div class=\"arrow_box_left\" style=\"margin-left:50px;\">            <div class=\"text1\"></div><div class=\"text\">".$swt_sec_msg."</div>        </div>    </div></div>';
if (sessionStorage['gc_have_new' + window.input_wd] != '1' && input_wd != \"\") {
	str += '<div style=\"margin-right:10px;\" class=\"msg-box\">    <div class=\"msg-client\">  <div class=\"client-avatar\"><img src=\"".$swt_cus_head."\" style=\"width:36px;\" width=\"40px\"></div>      <div class=\"arrow_box\">            <div class=\"text\">' + input_wd + '</div>        </div>    </div></div>';
}

jQuery(\"#chatMessageArea\").prepend(str);
jQuery(\".bubble-prologue\").remove();
jQuery(\".msg-system\").remove();

var count = 0,delete_max = 0,is_have = false;
function func_swt() {
jQuery(\".msg-box .text1\").each(function() {

	if (count < 50) {
		
		try {
			if (jQuery(this).html().length > 1) {
				jQuery(this).closest(\".msg-box\").each(function() {
					if (++delete_max < 3) {
						
						console.log(jQuery(this).html());
						jQuery(this).remove();
					}

				});
			}
		} catch (exx) {

		}
	}

	jQuery(this).closest(\".msg-box\").find(\".agent-avatar img\").each(function() {
		if (jQuery(this).attr(\"src\") != '".$swt_doc_head."') {
			jQuery(this).attr(\"width\", \"40px\").attr(\"src\", '".$swt_doc_head."')
		}
	})

	jQuery(\".msg-client .client-avatar img\").each(function() {
		if (jQuery(this).attr(\"src\") != '".$swt_cus_head."') {
			jQuery(this).attr(\"width\", \"40px\").attr(\"src\", '".$swt_cus_head."')
		}
	})

});

if (count == 80 && (jQuery(\".arrow_box_left\").length == 2 || delete_max == 0)) {
	

	str = '<div class=\"msg-box\">    <div class=\"msg-agent\">        <div class=\"agent-avatar\">            <img src=\"".$swt_doc_head."\" width=\"40px\">        </div>        <div class=\"arrow_box_left\" style=\"margin-left:50px;\">            <div class=\"text1\"></div><div class=\"text\">".$swt_thr_msg."</div>        </div>    </div></div>';
	is_have = true;
	jQuery(\"#chatMessageArea\").append(str);
} else if (count == 400 && is_have && jQuery(\".arrow_box_left\").length == 3) {
	
	str = '<div class=\"msg-box\">    <div class=\"msg-agent\">        <div class=\"agent-avatar\">            <img src=\"".$swt_doc_head."\" width=\"40px\">        </div>        <div class=\"arrow_box_left\" style=\"margin-left:50px;\">            <div class=\"text1\"></div><div class=\"text\">".$swt_for_msg."</div>        </div>    </div></div>';
	jQuery(\"#chatMessageArea\").append(str);
}

count++;
setTimeout(func_swt, 50);

}
func_swt();

	
function send_swt() {
	if (window.input_wd != undefined && window.input_wd != \"\") {
		if (sessionStorage['gc_have_new' + window.input_wd] != '1') {
			
			setTimeout(function() {
				jQuery.ajax({
					\"url\": \"/LR/CdCheck.aspx?sid1=\"+window.LR_sid,
					\"type\": \"POST\",
					\"data\": {
						\"id\": window.LR_siteid,
						\"sid\": window.LR_sid,
						\"maxid\": window.MaxID,
						\"_text\": \",ACT_TEMP|1|,\" + encodeURIComponent(window.input_wd),
						\"lng\": lng,
						\"pp\": window.LRppid
					},
					\"success\": function() {}
				});
				sessionStorage['gc_have_new' + window.input_wd] = 1;
			}, 500)
		}
	}
}




if (window.input_wd != \"\") {
	send_swt();
}
";
	
}

echo json_encode($arr_res);
?>